package test;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 33013
 * Date: 2023-03-14
 * Time: 22:14
 */
public class MyJFrame extends JFrame implements ActionListener {


    JButton jButton1 = new JButton("点我啊");
    JButton jButton2 = new JButton("再点我啊");

    public MyJFrame() {
        //设置界面宽高
        this.setSize(603,608);

        //设置界面标题
        this.setTitle("拼图游戏单机版 v1.0");

        //设置界面置顶
        this.setAlwaysOnTop(true);

        //设置界面居中
        this.setLocationRelativeTo(null);

        //关闭模式
        this.setDefaultCloseOperation(3);

        //取消默认的居中方式

        this.setLayout(null);

        jButton1.setBounds(0,0,100,50);
        jButton1.addActionListener(this);

        jButton2.setBounds(0,0,100,50);
        jButton2.addActionListener(this);

        //this.getContentPane().add(jButton1);
        this.getContentPane().add(jButton2);

        this.setVisible(true);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        Object souce = e.getSource();

        if (souce == jButton1){
            jButton1.setSize(200,200);
        }else {
            Random random = new Random();
            jButton2.setLocation(random.nextInt(500),random.nextInt(500));
        }
    }
}
